% create an image for parameters called in the mod filew

format long
param_string = 'empty';

for j=1:length(M_.param_names)
    temp1         = [M_.param_names(j,:),' = ',num2str(M_.params(j,:),15)];
    temp2         = [temp1,';'];
    param_string  = char(param_string,temp2);
    
end
param_string(1,:) = [];



fid  = fopen( [filenameModel,'.mod']);
C    = textscan(fid, '%s', 'Delimiter', '\n');
fclose(fid);

for j=1:length(M_.param_names)
    line_name              = M_.param_names(j,:);
    line_number            = strmatch(line_name, C{1});
    if size(line_number,1)>1
       line_number = line_number(2);
    end    
    line_change            = param_string(j,:);
    C{1}{line_number}      = line_change;
end        


% % var_zP = stdzP^2;
% % 
% % line_name              = 'vcov';
% % line_number            = strmatch(line_name, C{1});
% % line_change            = ['vcov = [',num2str(var_zP,15), ' 0 0;'];
% % C{1}{line_number}      = line_change;
% % 
% % 
% % var_uP = stdzuP^2;
% % 
% % line_name              = '0 1';
% % line_number            = strmatch(line_name, C{1});
% % line_change            = ['0 ',num2str(var_uP,15), ' 0;'];
% % C{1}{line_number}      = line_change;
% % 
% % 
% % var_ztildaP            = stdzP^2;
% % 
% % line_name              = '0 0';
% % line_number            = strmatch(line_name, C{1});
% % line_change            = ['0 0 ',num2str(var_ztildaP,15),'];'];
% % C{1}{line_number}      = line_change;


var_zP = stdzP^2;

line_name              = 'vcov';
line_number            = strmatch(line_name, C{1});
line_change            = ['vcov = [',num2str(var_zP,15), ' 0;'];
C{1}{line_number}      = line_change;


var_uP = stdzuP^2;

line_name              = '0 1';
line_number            = strmatch(line_name, C{1});
line_change            = ['0 ',num2str(var_uP,15), '];'];
C{1}{line_number}      = line_change;




fid_out=fopen( [filenameModel,'.mod'],'wt');
fprintf(fid_out,'%s\n',C{1}{:});
fclose(fid_out);
